package com.gec.anan.driver.service.impl;

import com.gec.anan.common.execption.AnanException;
import com.gec.anan.common.result.ResultCodeEnum;
import com.gec.anan.driver.client.DriverInfoFeignClient;
import com.gec.anan.driver.service.LocationService;
import com.gec.anan.map.client.LocationFeignClient;
import com.gec.anan.model.entity.driver.DriverSet;
import com.gec.anan.model.form.map.OrderServiceLocationForm;
import com.gec.anan.model.form.map.UpdateDriverLocationForm;
import com.gec.anan.model.form.map.UpdateOrderLocationForm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class LocationServiceImpl implements LocationService {

    @Autowired
    private LocationFeignClient locationFeignClient;

    @Autowired
    private DriverInfoFeignClient driverInfoFeignClient;

    /**
     * 司机开启接单服务
     *
     * @param updateDriverLocationForm
     * @return
     */
    @Override
    public Boolean updateDriverLocation(UpdateDriverLocationForm updateDriverLocationForm) {
        //获取司机个性化设置
        DriverSet driverSet = driverInfoFeignClient.getDriverSet(updateDriverLocationForm.getDriverId()).getData();
        if (driverSet.getServiceStatus() == 0) {
            throw new AnanException(ResultCodeEnum.NO_START_SERVICE);
        }
        log.info("更新司机位置信息");
        return locationFeignClient.updateDriverLocation(updateDriverLocationForm).getData();
    }

    //更新司机位置
    @Override
    public Boolean updateOrderLocationToCache(UpdateOrderLocationForm updateOrderLocationForm) {

        return locationFeignClient.updateOrderLocationToCache(updateOrderLocationForm).getData();
    }
   //司机上传位置
    @Override
    public Boolean saveOrderServiceLocation(List<OrderServiceLocationForm> orderLocationServiceFormList) {
        return locationFeignClient.saveOrderServiceLocation(orderLocationServiceFormList).getData();
    }
}
